﻿using System.IO;
using System.Reflection;

namespace Ooaavee.Scripting
{
    /// <summary>
    /// A script template.
    /// </summary>
    internal sealed class Template
    {
        /// <summary>
        /// No public constructor available, use GetTemplate method.
        /// </summary>
        private Template() { }

        /// <summary>
        /// A programming language.
        /// </summary>
        internal Language Language { set; get; }

        /// <summary>
        /// The full template text.
        /// </summary>
        internal string FullTemplateText { set; get; }

        /// <summary>
        /// Gets a <see cref="Template"/> for the specified programming language.
        /// </summary>
        /// <param name="language">a programming language</param>
        /// <returns>template</returns>
        internal static Template GetTemplate(Language language)
        {
            string name = string.Format("Ooaavee.Scripting.Templates.{0}.template", language);

            string text;
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    text = reader.ReadToEnd();
                }
            }

            return new Template { Language  = language, FullTemplateText = text };
        }
    }
}
